package com.tang.multi.v3;

import lombok.SneakyThrows;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.StandardSocketOptions;
import java.nio.channels.ServerSocketChannel;

/**
 * @author Tang
 * @classname Rector
 * @description [  ]
 * @date 2021/8/10 13:58
 */
public class Rector implements Runnable {

    private ServerSocketChannel serverSocketChannel;

    private Acceptor acceptor;

    public Rector(int port) throws IOException {
        this.serverSocketChannel = ServerSocketChannel.open();
        this.serverSocketChannel.configureBlocking(true);
        this.serverSocketChannel.bind(new InetSocketAddress("127.0.0.1", port));
        this.serverSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 128);
    }

    @SneakyThrows
    @Override
    public void run() {
        Thread thread = new Thread(new Acceptor(this.serverSocketChannel));
        thread.setDaemon(true);
        thread.start();
    }

}